(in-package :ws-sql)
;;;; $Id: parse-xml.lisp 2478 2007-06-07 15:39:53Z mev $
(declaim (optimize (debug 3) (safety 3)))

(defun lxml-get-tag (lxml)
  "Return the XML tag symbol of the lxml XML DOM"
  (cond ((symbolp lxml) lxml)
        ((stringp lxml) '())
        ((symbolp (first lxml)) (first lxml))
        (t (first (first lxml)))))

(defun lxml-find-tag (tag lxml)
  "Find a specific tag in a lxml XML DOM list"
  (find tag lxml :key #'lxml-get-tag))

(defpackage :jdbc (:nicknames "jdbc")
	    (:export "uri" "password" "username"))
(s-xml:register-namespace "urn:org.not.etel.jdbc-config" "jdbc" :jdbc)

(defun database-alist-from-file (filename)
  ;;; XXX deal with namespaces
  (let ((xml (s-xml:parse-xml-file filename))
	(result '()))
    (push (cons 'uri (second (lxml-find-tag 
			      '|jdbc|:|uri| xml))) result)
    (push (cons 'password (second (lxml-find-tag 
				   '|jdbc|:|password| xml))) result)
    (push (cons 'username (second (lxml-find-tag
				   '|jdbc|:|username| xml))) result)
    result))

